import request from '@/utils/request'
import type {
  ResponseUserList,
  addOrUpdateUserData,
  ResponseRole,
  setUserRoleRequestData,
} from './type'

enum Api {
  userList = '/admin/acl/user/',
  // 添加用户
  addUser = '/admin/acl/user/save/',
  updateUser = '/admin/acl/user/update/',
  // 获取用户职位
  userRole = '/admin/acl/user/toAssign/',
  // 设置用户职位
  setUserRole = '/admin/acl/user/doAssignRole/',
  // 删除当前一个用户
  deleteCurUser = '/admin/acl/user/remove/',
  deleteSelectUSers = '/admin/acl/user/batchRemove/',
}

export const reqUserList = (
  pageNo: number,
  pageSize: number,
  username: string,
) => {
  return request.get<any, ResponseUserList>(
    Api.userList + `${pageNo}/${pageSize}/?username=${username}`,
  )
}
export const reqAddOrUpdateUser = (data: addOrUpdateUserData) => {
  if (data.id) request.put<any, any>(Api.updateUser, data)
  request.post<any, any>(Api.addUser, data)
}

export const reqAllRoleAndCurUserRole = (id: number) => {
  return request.get<any, ResponseRole>(Api.userRole + id)
}
export const reqSetUserRole = (data: setUserRoleRequestData) => {
  return request.post<any, any>(Api.setUserRole, data)
}

export const reqDeleteCurUser = (id: number) => {
  return request.delete<any, any>(Api.deleteCurUser + id)
}
export const reqDeleteSelectUsers = (ids: number[]) => {
  return request.delete<any, any>(Api.deleteSelectUSers, { data: ids })
}
